home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / quartz / quartz10.lha / src / runtime / profile.h < prev    next >
C/C++ Source or Header  |  1990-04-29  |  4KB  |  156 lines

  1. /* Global (and some not so global) profiling data structures */
  2.  
  3. #ifndef InitIdStackSize        /* allow user to reset this */
  4. #define InitIdStackSize 50
  5. #endif
  6.  
  7. #define MaxProfilers    (NUMPROCS/2)
  8.  
  9. #define bclear(p,t,n) bzero((char *)(p), (unsigned int)(sizeof(t) * (n)))
  10.  
  11. /* Status of synch vars */
  12. #define ACTIVE            0
  13. #define DISCARDED        1
  14.  
  15. typedef struct id_stack_entry {
  16.     unsigned int procID;
  17.     unsigned int returnPC;
  18.     } IdStackEntry;
  19.  
  20. typedef struct child_data {
  21.     unsigned int type;
  22.     BusyData busy;
  23.     int calleeID;
  24.     struct child_data *next;
  25.     } ChildData;
  26.  
  27. #define ChildTableInit(p,n)  {\
  28.     int i; \
  29.     bclear(p,ChildData,n); \
  30.     for (i = 0; i < (n); i++) \
  31.         ((p) + i)->type = ChildDataType; \
  32.     }
  33.  
  34. typedef struct concurrent_data {
  35.     unsigned int type;
  36.     int hit[MaxProfilers];
  37.     SpinLock lock;
  38.     BusyData busy;
  39.     NominalData nom;
  40.     ChildData kid;
  41.     } ConcurrentData;
  42.  
  43. #define ConDataTableInit(p,n)  {\
  44.     int i; \
  45.     bclear(p,ConcurrentData,n); \
  46.     for (i = 0; i < (n); i++) { \
  47.         ((p) + i)->type = ConcurrentDataType; \
  48.         ((p) + i)->kid.type = ChildDataType; \
  49.         } \
  50.     }
  51.  
  52. typedef struct synch_samples {
  53.     ConcurrentData data;
  54.     QueueLength queue;
  55.     } SynchSamples;
  56.  
  57. #define SynchTableInit(p,n)  {\
  58.     int i; \
  59.     bclear(p,SynchSamples,n); \
  60.     for (i = 0; i < (n); i++) { \
  61.         ((p) + i)->data.type = ConcurrentDataType; \
  62.         ((p) + i)->data.kid.type = ChildDataType; \
  63.         } \
  64.     }
  65.  
  66. typedef struct graph_entry {
  67.     int    calleeID;
  68.     int    callerID;
  69.     int    num;
  70.     struct graph_entry *next;     /* DONT MOVE */
  71.     } GraphEntry;
  72.  
  73. #define GraphEntryInit(p)         bclear(p,GraphEntry,1)
  74. #define GraphTableInit(p,n)         bclear(p,GraphEntry,n)
  75.  
  76. typedef struct synch_profile
  77.     {
  78.     unsigned int type;
  79.     int status;
  80.     int kind;
  81.     struct thread *thread;
  82.  
  83.     char *name;            /* eg, the variable name */
  84.     int parentID;        /* who initialized me */
  85.  
  86.     struct synch_profile *next;
  87.  
  88.     int number[NumNumbers];
  89.     GraphEntry g;
  90.     SpinLock graphLock;
  91.  
  92.         /* used only by the dedicated processors */
  93.     usclk_t lastSample;
  94.     SynchSamples *samples;
  95.     struct synch_profile *dumpNext;
  96.     int synchId;
  97.     } SynchProfile;
  98.  
  99. #define AddNominal()    AtomicIncr(nominalParallelism)
  100. #define DecNominal()    AtomicDecr(nominalParallelism)
  101. #define NowBusy()        AtomicIncr(effectiveParallelism)
  102. #define NowIdle()        AtomicDecr(effectiveParallelism)
  103.  
  104.  
  105. #define PushOnIdStack(p,s)            TPushOnIdStack(pP.thread,p,s)
  106. #define PopOffIdStack()                pP.thread->idStack.top--
  107.  
  108. #define TReplaceOnIdStack(t,p,s)   ((t)->idStack.top->procID = ((int)(p)) | (s))
  109. #define TSetState(t,s)                 ((t)->idStack.top->procID |= (s))
  110. #define TClearState(t,s)             ((t)->idStack.top->procID &= (s))
  111.  
  112. #define ReplaceOnIdStack(p,s)         TReplaceOnIdStack(pP.thread,p,s)
  113. #define TSetStateReady(t)            TSetState(t,ReadyState)
  114. #define SetStateSpin()                TSetState(pP.thread,SpinState)
  115. #define SetStateBlocked()            TSetState(pP.thread,BlockedState)
  116. #define SetStateBusy()                TClearState(pP.thread,StateOffMask)
  117. #define SetStateOverhead()            TSetState(pP.thread,OverheadState)
  118. #define SetStateNormal()            TClearState(pP.thread,OverheadOffMask)
  119. #define TSetStateNormal(t)            TClearState(t,OverheadOffMask)
  120.  
  121. #define    isSynchID(s)    ((s) > mNumProcIds)
  122. #define    isOverhead(s)    (((s) & OverheadState) || (s) == NoID)
  123. #define    isSpinning(s)    (((s) & StateMask) == SpinState)
  124. #define    isBusy(s)        (((s) & StateMask) == BusyState)
  125. #define    isBlocked(s)    (((s) & StateMask) == BlockedState)
  126.  
  127. #define id2lock(p) \
  128.     (isSynchID(p) ? &((SynchProfile *)(p))->graphLock : &pcTableLocks[(p)])
  129.  
  130. #define SynchDispose(p)        ((p)->status = DISCARDED)
  131.  
  132. /* communication between normal and dedicated processors */
  133. extern private int profileOn;
  134.  
  135. extern shared int effectiveParallelism;
  136. extern shared int nominalParallelism;
  137. extern shared GraphEntry *pcTable;
  138. extern shared int pcTableSize;
  139.  
  140. /* info passed into dump routines */
  141. extern private int mNumProcIds;
  142.  
  143. extern shared FLOAT timeDiff;
  144. extern shared int numSamples;
  145.  
  146. extern shared ConcurrentData *procData;
  147.  
  148.  
  149. void TPushOnIdStack(), CallAndReplaceOnIdStack();
  150. void ProfileInit(), ProfileStart(), ProcessorListInit(), ProfileSetAllBusy();
  151. void ProfileExternal(), ProfileFinish();
  152. void SynchpoolInit(), ProfileMustAdd(), DumpInfo();
  153.  
  154. int GetMyId();
  155. SynchProfile *SynchInit();
  156.